package com.x.Part1_继承Thread类实现多线程;

/**
 * ClassName: EvenNumberTest
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.03.24 21:03
 */

public class EvenNumberTest {
    public static void main(String[] args) {
        PrintNumber t1 = new PrintNumber("线程1");
        PrintNumber t2 = new PrintNumber("线程2");
        t1.setName("子线程1");
        t2.setName("子线程2");


        t1.start();//线程开始执行，调用run方法
        Thread.currentThread().setName("main线程");

        for(int i=0;i<100;i++){

            if(i%2 == 0)
                System.out.println(Thread.currentThread().getName()+": ***************");
        }

        t2.start();

        System.out.println(Thread.currentThread());
    }
}

class  PrintNumber extends Thread{

    public PrintNumber(){}

    public PrintNumber(String name){
        super(name);
    }

    public PrintNumber(Runnable t,String name){
        super(t,name);
    }

    @Override
    public void run() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        for(int i=0;i<100;i++){
            if(i%2 == 0)
                System.out.println(Thread.currentThread().getName() +":"+ i);
        }
    }

    /*@Override
    public synchronized void start() {
        super.start();
    }*/
}